package org.yn.mkt.controller;

import org.yn.mkt.service.IBusinessRemarkService;
import org.yn.mkt.domain.BusinessRemark;
import org.yn.mkt.query.BusinessRemarkQuery;
import org.yn.base.util.AjaxResult;
import org.yn.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.yn.auth.annotation.PermissionAnnotation;
import java.util.List;

@PermissionAnnotation(name="businessRemark管理",descs = "businessRemark管理")
@Api("businessRemark管理接口")
@RestController
@RequestMapping("/businessRemark")
public class BusinessRemarkController {
    @Autowired
    public IBusinessRemarkService businessRemarkService;


    /**
     * 保存和修改公用的
     * @param businessRemark  传递的实体
     * @return Ajaxresult转换结果
     */
    @PermissionAnnotation(name="保存和修改BusinessRemark",descs = "保存和修改BusinessRemark")
    @ApiOperation(value = "保存和修改")
    @PostMapping
    public AjaxResult updateOrInsert(@RequestBody BusinessRemark businessRemark){
        try {
            if( businessRemark.getId()!=null)
                businessRemarkService.update(businessRemark);
            else
                businessRemarkService.insert(businessRemark);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("保存对象失败！"+e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @PermissionAnnotation(name="删除BusinessRemark",descs = "删除BusinessRemark")
    @ApiOperation(value = "删除")
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            businessRemarkService.delete(id);
            return AjaxResult.success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.error("删除对象失败！"+e.getMessage());
        }
    }
	
    //获取用户
    @PermissionAnnotation(name="获取单个BusinessRemark",descs = "获取单个BusinessRemark")
    @ApiOperation(value = "获取单个BusinessRemark")
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable("id") Long id)
    {
        try {
            BusinessRemark businessRemark = businessRemarkService.selectById(id);
            return AjaxResult.success(businessRemark);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取一个失败！"+e.getMessage());
        }
    }


    /**
    * 查看所有的XX信息
    * @return
    */
    @PermissionAnnotation(name="获取所有BusinessRemark",descs = "获取所有BusinessRemark")
    @ApiOperation(value = "获取所有BusinessRemark")
    @GetMapping
    public AjaxResult selectAll(){

        try {
            List< BusinessRemark> list = businessRemarkService.selectAll();
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取所有失败！"+e.getMessage());
        }
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageInfo 分页对象
    */
    @PermissionAnnotation(name="分页查询BusinessRemark",descs = "分页查询BusinessRemark")
    @ApiOperation(value = "分页查询BusinessRemark")
    @PutMapping
    public AjaxResult queryPage(@RequestBody BusinessRemarkQuery query)
    {
        try {
            PageInfo<BusinessRemark> pageInfo = businessRemarkService.queryPage(query);
            return AjaxResult.success(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取分页数据失败！"+e.getMessage());
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PermissionAnnotation(name="批量删除BusinessRemark",descs = "批量删除BusinessRemark")
    @ApiOperation(value = "批量删除BusinessRemark")
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        try {
                businessRemarkService.batchDelete(ids);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("批量删除失败"+e.getMessage());
        }
    }
}
